package com.zbkj.admin.controller.platform;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.merchant.MerchantIncomeExpenditure;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.MerchantIncomeExpenditureRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.merchant.MerchantCategoryRequest;
import com.zbkj.common.response.MerchantIncomeExpenditureResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.MerchantIncomeExpenditureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: 大粽子
 * @Date: 2024/5/29 11:14
 * @Description: 商户的收支明细记录
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/merchant/incomeExpenditure")
@Api(tags = "移动端商家管理 - 商户的收支明细记录") //配合swagger使用
public class MerchantIncomeExpenditureController {

    @Autowired
    private MerchantIncomeExpenditureService incomeExpenditureService;

    @ApiOperation(value = "收支明细分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MerchantIncomeExpenditure>> getList(@Validated MerchantIncomeExpenditureRequest request,
                                                                       @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(incomeExpenditureService.getList(request, pageParamRequest)));
    }

    @ApiOperation(value = "收支明细详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<MerchantIncomeExpenditureResponse> info(@PathVariable(value = "id") Integer id) {
        return CommonResult.success(incomeExpenditureService.getById(id));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "编辑商户分类")
    @ApiOperation(value="审核商户提现信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<Object> update(@RequestBody @Validated MerchantIncomeExpenditure request) {
        if (incomeExpenditureService.updateIncomeExpenditure(request)) {
            return CommonResult.success("编辑商户分类成功");
        }
        return CommonResult.failed("编辑商户分类失败");
    }
}
